/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fertigproz.models;

import fertigproz.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author zimmbi
 */
public class BaseTableModel extends DefaultTableModel {

    public MySQLDriver mysql;
    protected ResultSet results;
    protected String query;

    public BaseTableModel(MySQLDriver mysql) {
        super();
        this.mysql = mysql;
    }

    public void setQuery(String query) {
        this.query = query;
    }

    public void requery() {
        try {
            results = mysql.query(query);
            fireTableDataChanged();
        } catch (SQLException ex) {
        }
    }

    @Override
    public int getRowCount() {
        if (results != null) {
            try {
                results.last();
                return results.getRow();
            } catch (SQLException ex) {
            }
        }
        return 0;
    }
}
